package com.bcxk.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bcxk.common.CookieUtil;
import com.bcxk.common.Respond;
import com.bcxk.entity.dto.Destination;
import com.bcxk.service.DestService;
import com.bcxk.service.HomeStayService;
import com.bcxk.util.EsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("minsu")
public class MinSuController {

    @Resource
    DestService destService;
    @Resource
    HomeStayService homeStayService;

    @RequestMapping("getTest")
    public String getTest(String name){
        return name;
    }

    /**
     * 获取所有目的地信息
     * @return
     */
    @RequestMapping("getDest")
    public Respond getDest(){
        QueryWrapper<Destination> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByAsc(Destination::getOrderNum);
        return Respond.ok(destService.list(wrapper));
    }

    /**
     * 根据目的地名称查询该目的地下的所有民宿信息，并分页
     * @param destName
     * @param pageNum
     * @return
     */
    @RequestMapping("getMinSuByDestName")
    public Respond getMinSuByName(String destName,int pageNum){
        return Respond.ok(homeStayService.getMinSuListByName(destName,pageNum));
    }

    /**
     * 根据民宿id查询该民宿所有信息（包括房间，评论，房间设施，民宿图片等）
     * @param minsuId
     * @return
     */
    @RequestMapping("getMinSuById")
    public Respond getMinSuById(Long minsuId){
        return Respond.ok(homeStayService.getMinSuByMinSuId(minsuId));
    }

    @Autowired
    EsUtils esUtils;

    @RequestMapping("getMinSuByEs")
    public Respond getMinSuByEs(String word) throws IOException {
        List<String> list = esUtils.query("homestay", "minsuname", word);
        return Respond.ok(list);
    }
}
